package Lee_code;

import java.util.HashMap;

public class Lee_454 {

    public int fourSumCount(int[] nums1, int[] nums2, int[] nums3, int[] nums4) {
        int len = nums1.length;
        if(len==0)
            return 0;
        int count = 0;

        //创建哈希表, Key是相加的和, Value是该和出现的次数
        HashMap<Integer, Integer> hashMap_12 = new HashMap<>();
        HashMap<Integer, Integer> hashMap_34 = new HashMap<>();

        for(int i=0; i<len; i++)
        {
            for(int j=0; j<len; j++)
            {
                int key = nums1[i] + nums2[j];
                hashMap_12.put(key,hashMap_12.getOrDefault(key,0)+1);
            }
        }

        for(int i=0; i<len; i++)
        {
            for(int j=0; j<len; j++)
            {
                int key = nums3[i] + nums4[j];
                hashMap_34.put(key,hashMap_34.getOrDefault(key,0)+1);
            }
        }


        for(int i: hashMap_12.keySet())
        {
            for (int j: hashMap_34.keySet())
            {
                if(i+j==0)
                {
                    count = count + hashMap_12.get(i)*hashMap_34.get(j);
                }
            }
        }
        return count;
    }
    public static void main(String[] args) {

    }
}
